package com.transpeed.payservice.Utils;

import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;

import com.google.gson.Gson;

/**
 * @author zhuli json类处理
 */
public class ConstructJsonUtils {
	private static Gson gson = new Gson();

	// 判断是否为空
	public static boolean isNotNull(String txt) {
		// System.out.println("Inside isNotNull");
		return txt != null && txt.trim().length() >= 0 ? true : false;
	}

	// bean转json
	public static String beanToJson(Object obj) throws JSONException {
		return gson.toJson(obj);

	}

	// list转json
	public static String listToJson(Object listobj) throws JSONException {
		return gson.toJson(listobj);

	}

	// 失败
	public static String constructJSON(boolean success, String data) {
		JSONObject obj = new JSONObject();
		try {
			obj.put("success", success);
			obj.put("data", data);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
		}
		return obj.toString();
	}
}
